package leetcode.code1283;

public class Solution {
	public int smallestDivisor(int[] nums, int threshold) {
		int len = nums.length;
		int l = 1, r = 1000000;
		int ans = 0;
		while (l <= r) {
			int mid = l + ((r - l) >> 1);
			long sum = 0;
			for (int i = 0; i < len; i++) {
				int num = nums[i];
				sum += 1l * (num + mid - 1) / mid;
			}
			if (sum <= threshold) {
				ans = mid;
				r = mid - 1;
			} else {
				l = mid + 1;
			}
		}
		return ans;
	}
}
